<template>
  <div>
    <el-table ref="table" :data="list" style="width: 100%" border v-loading="loading">
      <el-table-column width="50" label="序号" key="1" header-align="center" align="center">
        <template slot-scope="scope">
          <div>{{$parent.params.per_limit*($parent.params.page-1)+scope.$index+1}}</div>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="center" key="2" prop="id" label="ID" width="50"></el-table-column>
      <el-table-column
        header-align="center"
        key="3"
        align="center"
        prop="merchant_no"
        label="商户编号"
        width="130"
      ></el-table-column>
      <el-table-column
        key="4"
        header-align="center"
        align="center"
        prop="agent_info"
        label="代理信息"
        show-overflow-tooltip
        width="120"
      ></el-table-column>
      <el-table-column
        key="5"
        header-align="center"
        align="center"
        prop="merchant_name"
        show-overflow-tooltip
        label="展示名"
        width="90"
      ></el-table-column>
      <el-table-column
        key="25"
        header-align="center"
        align="center"
        prop="sign_name"
        show-overflow-tooltip
        label="签约名"
        width="90"
      ></el-table-column>
      <el-table-column
        key="6"
        header-align="center"
        align="center"
        prop="merchant_type_name"
        show-overflow-tooltip
        label="商户类型"
        width="100"
      ></el-table-column>
      <el-table-column
        key="7"
        header-align="center"
        align="center"
        show-overflow-tooltip
        prop="lp_name"
        label="法人"
        width="80"
      ></el-table-column>
      <el-table-column
        key="8"
        header-align="center"
        align="center"
        prop="address_info"
        show-overflow-tooltip
        label="所在地址"
        width="110"
      ></el-table-column>
      <el-table-column
        key="9"
        header-align="center"
        align="center"
        prop="linkman_phone"
        label="联系人电话"
        width="100"
      ></el-table-column>
      <el-table-column
        key="10"
        header-align="center"
        align="center"
        show-overflow-tooltip
        prop="account_type_name"
        label="结算类型"
        width="95"
      ></el-table-column>
      <el-table-column
        key="11"
        header-align="center"
        align="center"
        prop="holder_name"
        label="开户人"
        width="100"
      ></el-table-column>
      <el-table-column
        key="12"
        header-align="center"
        align="center"
        show-overflow-tooltip
        prop="card_info"
        label="结算卡信息"
        width="90"
      ></el-table-column>
      <el-table-column
        key="13"
        header-align="center"
        align="center"
        prop="turnover_amount"
        label="总金额（元）"
        width="100"
      ></el-table-column>
      <el-table-column
        key="14"
        header-align="center"
        align="center"
        prop="enable_name"
        label="状态"
        width="80"
      ></el-table-column>
      <el-table-column
        key="15"
        header-align="center"
        align="center"
        prop="opened_at"
        label="进件通过时间"
        width="140"
      ></el-table-column>
      <el-table-column
        key="16"
        header-align="center"
        align="center"
        prop="created_at"
        label="创建时间"
        width="140"
      ></el-table-column>
      <el-table-column
        key="17"
        fixed="right"
        header-align="center"
        align="center"
        label="操作"
        width="210"
      >
        <template slot-scope="scope">
          <el-button
            @click="thawOrfrozen(scope.row)"
            v-if="searchInterface('merchants.enable')"
            type="text"
          >{{scope.row.is_enable===0?'解冻':'冻结'}}</el-button>
          <el-button
            type="text"
            v-if="searchInterface('merchant_settle_cards.change')"
            @click="changeCard(scope.row)"
          >修改结算银行卡</el-button>
          <el-button
            type="text"
            v-if="searchInterface('merchant_settle_changes.detail')"
            @click="seeDetail(scope.row)"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 门店信息 -->
    <el-dialog title="门店信息" :visible.sync="store_dialog" width="40%">
      <el-form label-position="right" label-width="130px" style="width:350px;margin:0 auto">
        <el-form-item label="三证合一营业执照" v-if="storeInfo.unified_certificate">
          <img class="img" :src="storeInfo.unified_certificate" />
        </el-form-item>
        <el-form-item label="营业执照" v-if="storeInfo.business_license	">
          <img class="img" :src="storeInfo.business_license	" />
        </el-form-item>
        <el-form-item label="门头照" v-if="storeInfo.sign_board">
          <img class="img" :src="storeInfo.sign_board" />
        </el-form-item>
        <el-form-item label="室内照" v-if="storeInfo.interior_photo	">
          <img class="img" :src="storeInfo.interior_photo	" />
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 认证信息 -->
    <el-dialog title="认证信息" :visible.sync="authentication_dialog" width="40%">
      <el-form label-position="right" label-width="130px" style="width:350px;margin:0 auto">
        <el-form-item label="开户许可证" v-if="storeInfo.permit_bank_account">
          <img class="img" :src="storeInfo.permit_bank_account" />
        </el-form-item>
        <el-form-item label="法人身份证正面" v-if="storeInfo.lp_idcard_front">
          <img class="img" :src="storeInfo.lp_idcard_front" />
        </el-form-item>
        <el-form-item label="法人身份证反面" v-if="storeInfo.lp_idcard_backend">
          <img class="img" :src="storeInfo.lp_idcard_backend" />
        </el-form-item>
        <el-form-item label="手持身份证" v-if="storeInfo.handheld_idcard">
          <img class="img" :src="storeInfo.handheld_idcard" />
        </el-form-item>
        <el-form-item label="手持银行卡" v-if="storeInfo.handheld_bankcard	">
          <img class="img" :src="storeInfo.handheld_bankcard" />
        </el-form-item>
        <el-form-item label="结算卡" v-if="storeInfo.settle_bankcard">
          <img class="img" :src="storeInfo.settle_bankcard" />
        </el-form-item>
        <el-form-item label="结算人身份证正面" v-if="storeInfo.settler_idcard_front	">
          <img class="img" :src="storeInfo.settler_idcard_front" />
        </el-form-item>
        <el-form-item label="结算人身份证反面" v-if="storeInfo.settler_idcard_backend">
          <img class="img" :src="storeInfo.settler_idcard_backend" />
        </el-form-item>
        <el-form-item label="结算账户指定书" v-if="storeInfo.auth_for_settlement">
          <img class="img" :src="storeInfo.auth_for_settlement" />
        </el-form-item>
        <el-form-item label="特殊资质证照图片" v-if="storeInfo.special_other_license">
          <img class="img" :src="storeInfo.special_other_license" />
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
// 审核失败
import { thawOrfrozenMerchant } from '@/api/merchant-admin/admin'
export default {
  props: {
    list: {
      type: Array,
      required: true
    },
    status: {
      type: [Number, String],
      required: true
    },
    loading: {
      type: Boolean,
      required: true
    },
    callback: {
      type: Function,
      required: true,
      default: () => {}
    }
  },
  data() {
    return {
      storeInfo: {},
      store_dialog: false,
      authentication_dialog: false
    }
  },
  watch: {
    list() {
      setTimeout(() => {
        this.$refs.table.doLayout()
      })
    }
  },
  methods: {
    // 修改结算卡
    changeCard({ lp_name: name, id }) {
      this.$router.push({
        path: '/menu/merchant-admin/change-card',
        query: {
          name,
          id
        }
      })
    },
    // 查看详情
    seeDetail({ id }) {
      this.$router.push({
        path: '/menu/merchant-admin/admin-detail',
        query: {
          id
        }
      })
    },
    // 打开弹窗
    openDialog({ credential }, flag) {
      if (flag === 1) {
        this.store_dialog = true
      } else {
        this.authentication_dialog = true
      }
      this.storeInfo = credential
    },
    // 冻结||解冻操作
    thawOrfrozen({ id, is_enable }) {
      this.$confirm(
        `确认执行${is_enable === 0 ? '解冻' : '冻结'}操作吗?${
          is_enable === 1 ? '     冻结后的商户将不能收款' : ''
        }`,
        `${is_enable === 0 ? '解冻' : '冻结'}操作？`,
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(() => {
          thawOrfrozenMerchant({
            id,
            params: { enable: is_enable === 0 ? 1 : 0 }
          }).then(() => {
            this.$message({
              type: 'success',
              message: is_enable === 0 ? '已解冻' : '已冻结'
            })
            this.callback({
              id,
              is_enable: is_enable === 0 ? 1 : 0,
              enable_name: is_enable === 0 ? '正常' : '冻结'
            })
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.img {
  width: 170px;
  height: 170px;
  border-radius: 5px;
}
</style>